//
//  BBuyNowShopCell.m
//  DistributorAB
//
//  Created by LZY on 2019/10/9.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "BBuyNowShopCell.h"
#import "BShopPartModel.h"

@interface BBuyNowShopCell ()
@property (nonatomic, strong) UIImageView *ivShop;//产品图片
@property (nonatomic, strong) UILabel *lblDetail;//产品说明
@property (nonatomic, strong) UILabel *lblPrice;//省级显示价格
@property (nonatomic, strong) UIImageView *ivPay;//赔付金标志
@property (nonatomic, strong) UIImageView *ivQuality;//质保期标志
@property (nonatomic, strong) UIImageView *ivBuy;//我要预订标志
@end

@implementation BBuyNowShopCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViewAction];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}
#pragma mark - 界面布局方法
- (void)setupViewAction{
    UIImageView *ivBg = [UIImageView new];
    ivBg.image = imgname(@"shop_bg_icon");
    [self.contentView addSubview:ivBg];
    [ivBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.contentView);
    }];
    
    _ivShop = [UIImageView new];
    _ivShop.backgroundColor = kColorWithHex(0xf2f2f2);
    _ivShop.contentMode = UIViewContentModeScaleToFill;
    [self.contentView addSubview:_ivShop];
    [_ivShop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView.mas_leading).offset(22);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-22);
        make.top.equalTo(self.contentView.mas_top).offset(22);
        make.height.mas_equalTo((kScreen_Width - 44) * 0.53);
    }];
    
    UIImageView *ivLine = [UIImageView new];
    ivLine.image = imgname(@"shop_line_icon");
    [self.contentView addSubview:ivLine];
    [ivLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView.mas_leading).offset(4);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-4);
        make.top.equalTo(self.ivShop.mas_bottom);
        make.height.mas_equalTo(42);
    }];
    
    _lblDetail = [UILabel new];
    _lblDetail.numberOfLines = 2;
    _lblDetail.font = [UIFont systemFontOfSize:16];
    _lblDetail.textColor = kColorWithHex(0x333333);
    [self.contentView addSubview:_lblDetail];
    [_lblDetail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView.mas_leading).offset(29);
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-24);
        make.top.equalTo(ivLine.mas_bottom);
    }];
    
    if (AGENT_LEVEL == 1) {
        _lblPrice = [UILabel new];
        _lblPrice.font = [UIFont boldSystemFontOfSize:22];
        _lblPrice.textColor = kColorWithHex(0x70be68);
        [self.contentView addSubview:_lblPrice];
        [_lblPrice mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self.lblDetail.mas_leading);
            make.top.equalTo(self.lblDetail.mas_bottom).offset(10);
            make.height.mas_equalTo(30);
        }];
    }
    
    _ivPay = [UIImageView new];
    //_ivPay.image = imgname(@"shop_pay_logo_icon");
    _ivPay.image = imgname(@"butiegongshifei_cell");
    [self.contentView addSubview:_ivPay];
    [_ivPay mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView.mas_leading).offset(29);
        if (AGENT_LEVEL == 1) {
            make.top.equalTo(self.lblPrice.mas_bottom).offset(8);
        }else{
            make.top.equalTo(self.lblDetail.mas_bottom).offset(16);
        }
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-27);
        make.size.mas_equalTo(CGSizeMake(111, 22));
    }];
    
    _ivQuality = [UIImageView new];
    _ivQuality.image = imgname(@"shop_quality_logo_icon");
    [self.contentView addSubview:_ivQuality];
    [_ivQuality mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.ivPay.mas_centerY);
        make.leading.equalTo(self.ivPay.mas_trailing).offset(10);
        make.size.mas_equalTo(CGSizeMake(62, 22));
    }];
    
    _ivBuy = [UIImageView new];
    //_ivBuy.image = imgname(@"shop_buy_now_icon");
    _ivBuy.image = imgname(@"lijiyuding_cell");
    [self.contentView addSubview:_ivBuy];
    [_ivBuy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.equalTo(self.contentView.mas_trailing).offset(-17);
        make.centerY.equalTo(self.ivPay.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(107, 41));
    }];
}
#pragma mark - 数据更新
- (void)setModel:(BShopPartModel *)model{
    if (model) {
        _model = model;
        [HFTools imageViewUpdateWithUrl:model.image_url withImageView:_ivShop withPlaceholderImage:@""];
        _lblDetail.text = [NSString stringWithFormat:@"%@",model.parts_details];
        if (AGENT_LEVEL == 1) {
            _lblPrice.text = [NSString stringWithFormat:@"￥%@",model.salePrice];
        }
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
